Skip to content

Support IOS setup in AppDelegate.m#394

Merged
manuquentin merged 4 commits into
react-native-webrtc:masterfrom
Telzio:feature/ios-setup-in-appdelegate
May 2, 2021
Merged

Support IOS setup in AppDelegate.m#394
manuquentin merged 4 commits into
react-native-webrtc:masterfrom
Telzio:feature/ios-setup-in-appdelegate

Conversation

@jonastelzio

@jonastelzio jonastelzio commented Apr 5, 2021

Copy link
Copy Markdown
Contributor

On IOS, CallKit doesn't get it's delegate registered before actively calling .setup from react native, meaning that we'll never get any didLoadWithEvents fired for events such as answer and end, since CallKit simply isn't delegated to callkeep prior answering the call.

This PR exposes setup so it can be called from AppDelegate.m, allowing us to catch these events as soon as they happen.

Example of how to perform setup during AppDelegate initialization:

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ 
  self.bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:self.bridge
                                                   moduleName:@"App"
                                            initialProperties:nil];

  // ======== OTHER CODE REDACTED ==========

  // RNCallKeep setup should (probably?) be called before registering for PuskKit notifications
  [RNCallKeep setup:@{
    @"appName": @"Awesome App",
    @"maximumCallGroups": @3,
    @"maximumCallsPerCallGroup": @1,
    @"supportsVideo": @NO,
  }];

  // Register for pushkit. As soon as the delegates are registered, Pushkit events will fire.
  // It probably(?) doesn't happen syncronously, but RNCallKeep should probably be registered first
  [RNVoipPushNotificationManager voipRegistration];

  // ======== OTHER CODE REDACTED ==========
  
  return YES;
}

@Romick2005

Copy link
Copy Markdown

I did the same in my PR #382 (comment)

@jonastelzio

Copy link
Copy Markdown
Contributor Author

I did the same in my PR #382 (comment)

That pull request is really difficult to review because you changed indentation so many places in the file ;)

@Romick2005

Copy link
Copy Markdown

Yep, but that is just indentation and in should look better in a good diff viewer. I do that because I am convinced that more readable and more intuitive code would be better for everyone.

@danjenkins

Copy link
Copy Markdown
Collaborator

To be honest it doesn't matter what you think the indentation in the current project; it's good practice not to just go changing it, especially within a PR for another feature

@Romick2005

Copy link
Copy Markdown

I also don't care what you are thinking. I just prefer have better code in the repo that I need to use and that's it.

@danjenkins

Copy link
Copy Markdown
Collaborator

That's a great way to talk to one of the people that would approve your PR...

+ (BOOL)isCallActive:(NSString *)uuidString;

+ (void)setup:(NSDictionary *)options;

@jonastelzio jonastelzio Apr 5, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expose a static method to call setup from AppDelegate.m

if (self = [super init]) {
_isStartCallActionEventListenerAdded = NO;
_delayedEvents = [NSMutableArray array];
if (_delayedEvents == nil) _delayedEvents = [NSMutableArray array];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init is called repeatedly, deleting any events queued up here. This avoids that.

name, @"name",
body, @"data",
nil
];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body can be null for certain events, such as RNCallKeepDidActivateAudioSession which will fire before the bridge is up if answering a call really quickly!

Comment thread ios/RNCallKeep/RNCallKeep.m
supportsDTMF:(BOOL)supportsDTMF
supportsGrouping:(BOOL)supportsGrouping
supportsUngrouping:(BOOL)supportsUngrouping)
supportsUngrouping:(BOOL)supportsUngrouping)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever was sitting at the end of this line, xcode insists on deleting it when I save the file 🤷‍♂️

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace is the devil

@jonastelzio jonastelzio marked this pull request as ready for review April 6, 2021 08:31
@jonastelzio

jonastelzio commented Apr 7, 2021

Copy link
Copy Markdown
Contributor Author

Upon further investigation, it might be sufficient to just call [RNCallKeep initCallKitProvider] instead of setup, considering it's using NSUserDefaults to obtain these settings.

I'll make some testing and amend the PR if that's the case.

Edit:
Doing so would cause [self.callKeepProvider setDelegate:self queue:nil]; to be executed WHILE a call is ringing, which I doubt is how Apple intended for this library to be used(?)

@jonastelzio jonastelzio marked this pull request as draft April 7, 2021 13:22
@jonastelzio jonastelzio marked this pull request as ready for review April 7, 2021 15:18
@danjenkins

Copy link
Copy Markdown
Collaborator

@jonastelzio can you make changes to the README too? Other than that I've confirmed these changes work in a project so I'd be happy to approve once theres docs on using setup in app delegate

@jonastelzio

Copy link
Copy Markdown
Contributor Author

@jonastelzio can you make changes to the README too? Other than that I've confirmed these changes work in a project so I'd be happy to approve once theres docs on using setup in app delegate

Can do!

… only be ignored if initial setup was done in AppDelegate.m
@jonastelzio jonastelzio force-pushed the feature/ios-setup-in-appdelegate branch from 26c6990 to e5607f5 Compare April 9, 2021 12:19
RNCallKeep *callKeep = [RNCallKeep allocWithZone: nil];
[callKeep setup:options];
isSetupNatively = YES;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply allocate the singleton and call setup in there, setting isSetupNatively makes the library ignore further calls to setup from react native.

NSLog(@"[RNCallKeep][setup] already setup");
RCTLog(@"[RNCallKeep][setup] already setup in native code");
#endif
return;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we've already initialized from AppDelegate.m, we ignore further calls to setup from React Native.

@jonastelzio

Copy link
Copy Markdown
Contributor Author

@danjenkins I've added documentation and changed the behavior so we ONLY prevent repeated calls to .setup from react native IF the module is initially setup from native code. This way this push will never change any existing functionality.

@sboily sboily added the need review Need to review ticket label Apr 15, 2021
@sboily sboily assigned sboily and manuquentin and unassigned sboily Apr 15, 2021
@sboily sboily requested a review from manuquentin April 15, 2021 14:10
DanijelBojcic added a commit to DanijelBojcic/react-native-callkeep that referenced this pull request Apr 15, 2021
@gobzila

gobzila commented Apr 29, 2021

Copy link
Copy Markdown

Any updates on this? It would be great if this PR will be merged.

@manuquentin manuquentin merged commit 6323479 into react-native-webrtc:master May 2, 2021
@manuquentin

Copy link
Copy Markdown
Contributor

Thanks @jonastelzio !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need review Need to review ticket

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants